define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'luyoulog/index' + location.search,
                    add_url: 'luyoulog/add',
                    edit_url: 'luyoulog/edit',
                    del_url: 'luyoulog/del',
                    multi_url: 'luyoulog/multi',
                    import_url: 'luyoulog/import',
                    table: 'luyoulog',
                }
            });

            var table = $("#table");
            $.fn.bootstrapTable.locales[Table.defaults.locale]['formatShowingRows'] = function (pageFrom, pageTo, totalRows) {
                return ' ';
            };
            const columns = [
                {checkbox: true},
                //{field: 'id', title: __('Id')},
                {field: 'day', title: __('Day'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                {field: 'qiye', title: __('企业级ikuai'),operate: false },
                {field: 'tp_link', title: __('TP-LIAK'),operate: false },
                {field: 'yidong', title: __('移动-199'),operate: false },
                // field: 'qi_dangkou', title: __('(企业级)档口'),operate: false },
                // {field: 'qi_yi', title: __('(企业级)易剑伟'),operate: false },
                // {field: 'qi_zhong', title: __('(企业级)钟明锋'),operate: false },
                // {field: 'qi_zhuo', title: __('(企业级)卓大旺'),operate: false },
                // {field: 'qi_wu', title: __('(企业级)伍海鹏'),operate: false },
                // {field: 'qi_yang', title: __('(企业级)杨宇航'),operate: false },
                // {field: 'tp_dangkou', title: __('(TP-LIAK)档口'),operate: false },
                // {field: 'tp_yi', title: __('(TP-LIAK)易剑伟'),operate: false },
                // {field: 'tp_zhong', title: __('(TP-LIAK)钟明锋'),operate: false },
                // {field: 'tp_zhuo', title: __('(TP-LIAK)卓大旺'),operate: false },
                // {field: 'tp_wu', title: __('(TP-LIAK)伍海鹏'),operate: false },
                // {field: 'tp_yang', title: __('(TP-LIAK)杨宇航'),operate: false },
                // {field: 'yi_dangkou', title: __('(移动-199)档口'),operate: false },
                // {field: 'yi_yi', title: __('(移动-199)易剑伟'),operate: false },
                // {field: 'yi_zhong', title: __('(移动-199)钟明锋'),operate: false },
                // {field: 'yi_zhuo', title: __('(移动-199)卓大旺'),operate: false },
                // {field: 'yi_wu', title: __('(移动-199)伍海鹏'),operate: false },
                // {field: 'yi_yang', title: __('(移动-199)杨宇航'),operate: false },
                //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
            ]
            const typeMap = {qiye: '企业级', tp_link: 'TP-LIAK', yidong: '移动-199'}
            for (const i in typeMap) {
                    for (const empItem of empList) {
                    columns.push({field: `emp_${i}_${empItem.id}`, title: `(${typeMap[i]})${empItem.name}`, operate: false })
                }
            }
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                //pageSize: 35,
                columns: [columns]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Table.api.fixedheader(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
